package com.multi.thread.chapter01;

/**
 *	共享数据
 *	非线程安全主要是指多个线程对同一个对象中的同一个实例变量进行操作时会出现值被更改、值不同步的情况
 */
public class ShareThread extends Thread {
	
	private int count = 5;

	@Override
	synchronized public void run() {
		super.run();
		count--;
		System.out.println("由 " + Thread.currentThread().getName() + " 计算, count = " + count);
	}
	
	public static void main(String[] args) {
		ShareThread shareThread = new ShareThread();
		Thread threadA = new Thread(shareThread, "A");
		Thread threadB = new Thread(shareThread, "B");
		Thread threadC = new Thread(shareThread, "C");
		Thread threadD = new Thread(shareThread, "D");
		Thread threadE = new Thread(shareThread, "E");
		threadA.start();
		threadB.start();
		threadC.start();
		threadD.start();
		threadE.start();
	}

}
